<html>
    <head>
        <title>Edit Order</title>
    </head>
    <body>
        <h1>Edit Order</h1>
<?php
    // Connect to database
    $link = mysql_connect('localhost', 'root', 'wizapire');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    $db_selected = mysql_select_db('bentley', $link);
    if (!$db_selected) {
        die ('Can\'t use bentley : ' . mysql_error());
    }

    // BCON
    $bcon = htmlspecialchars($_GET["bcon"]);
    if (0 == preg_match("/^BC[0-9]{2}\-[0-9]{3}$/", $bcon)) {
        die('Illegal BCON: ' . $bcon);
    }
    
    // Query the order
    $query = sprintf("SELECT * FROM orders_view WHERE bcon='%s'", mysql_real_escape_string($bcon));
    $result = mysql_query($query);

    if (!$result) {
        $message  = 'Invalid query: ' . mysql_error() . "\n";
        $message .= 'Whole query: ' . $query;
        die($message);
    }

    // Display the form
    $row = mysql_fetch_assoc($result);
    echo '<form name="edit" action="edit.php" method="post">';
    echo '<div class="field">';
    echo '<p class="fieldname">BC ON: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="bcon" value="' . $row['bcon'] . '" /></p>';
    echo '</div>';
    echo '<div class="field">';
    echo '<p class="fieldname">Dealer Contract No.: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="dcn" value="' . $row['dcn'] . '" /></p>';
    echo '</div>';
    echo '<div class="field">';
    echo '<p class="fieldname">BML ON: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="bmlon" value="' . $row['bmlon'] . '" /></p>';
    echo '</div>';
    echo '<div class="field">';
    echo '<p class="fieldname">Dealer: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="dealername" value="' . $row['dealername'] . '" /></p>';
    echo '</div>';
    echo '<div class="field">';
    echo '<p class="fieldname">Customer: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="customer" value="' . $row['customer'] . '" /></p>';
    echo '</div>';
    echo '<div class="field">';
    echo '<p class="fieldname">Model: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="modelname" value="' . $row['modelname'] . '" /></p>';
    echo '</div>';
    echo '<div class="field">';
    echo '<p class="fieldname">Paint: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="paintname" value="' . $row['paintname'] . '" /></p>';
    echo '</div>';
    echo '<div class="field">';
    echo '<p class="fieldname">Options: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="options" value="' . $row['options'] . '" /></p>';
    echo '</div>';
    echo '<div class="field">';
    echo '<p class="fieldname">Chassis No.: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="chassis" value="' . $row['chassis'] . '" /></p>';
    echo '</div>';
    echo '<div class="field">';
    echo '<p class="fieldname">Engine No.: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="engine" value="' . $row['engine'] . '" /></p>';
    echo '</div>';
    echo '<div class="field">';
    echo '<p class="fieldname">PDI Date: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="pdi" value="' . $row['pdi'] . '" /></p>';
    echo '</div>';
    echo '<div class="field">';
    echo '<p class="fieldname">Wholesale Delivery Date: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="wholesale" value="' . $row['wholesale'] . '" /></p>';
    echo '</div>';
    echo '<div class="field">';
    echo '<p class="fieldname">Closures Date: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="closure" value="' . $row['closure'] . '" /></p>';
    echo '</div>';
    echo '<div class="field">';
    echo '<p class="fieldname">Retail Delivery Date: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="retail" value="' . $row['retail'] . '" /></p>';
    echo '</div>';
    echo '<div class="field">';
    echo '<p class="fieldname">ETD UK: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="etduk" value="' . $row['etduk'] . '" /></p>';
    echo '</div>';
    echo '<div class="field">';
    echo '<p class="fieldname">ETA SH: </p>';
    echo '<p class="fiedlvalue"><input type="text" name="etash" value="' . $row['etash'] . '" /></p>';
    echo '</div>';
    echo '<input type="submit" value="Submit" />';
    echo '</form>';

    mysql_free_result($result);
    mysql_close($link);

?>

    </body>
</html>
